{
  "properties" : { },
  "id" : "0def075ed26347f6bbeebacde0af5f00",
  "script" : null,
  "groupId" : "74af8e1135d2474eb9b6b4081e6d5967",
  "name" : "获取连线关系",
  "createTime" : 1727071056334,
  "updateTime" : 1726653329646,
  "lock" : "1",
  "createBy" : "ndmp",
  "updateBy" : "ndmp",
  "path" : "getLinkByDeptId",
  "method" : "GET",
  "parameters" : [ {
    "name" : "deptId",
    "value" : "0",
    "description" : "",
    "required" : true,
    "dataType" : "String",
    "type" : "",
    "defaultValue" : "",
    "validateType" : "",
    "error" : "",
    "expression" : "",
    "children" : [ ]
  }, {
    "name" : "flag",
    "value" : "1",
    "description" : null,
    "required" : false,
    "dataType" : "String",
    "type" : null,
    "defaultValue" : null,
    "validateType" : null,
    "error" : null,
    "expression" : null,
    "children" : null
  } ],
  "options" : [ ],
  "requestBody" : "",
  "headers" : [ ],
  "paths" : [ ],
  "responseBody" : "{\n    \"code\": 500,\n    \"success\": false,\n    \"data\": {},\n    \"msg\": \"系统维护中，请稍后重试。\"\n}",
  "description" : "",
  "requestBodyDefinition" : {
    "name" : "",
    "value" : { },
    "description" : "",
    "required" : false,
    "dataType" : "String",
    "type" : "",
    "defaultValue" : "",
    "validateType" : "",
    "error" : "",
    "expression" : "",
    "children" : [ ]
  },
  "responseBodyDefinition" : {
    "name" : "",
    "value" : { },
    "description" : "",
    "required" : false,
    "dataType" : "String",
    "type" : "",
    "defaultValue" : "",
    "validateType" : "",
    "error" : "",
    "expression" : "",
    "children" : [ ]
  }
}
================================
import org.springframework.util.CollectionUtils
import java.util.stream.Collectors

import "@/util/reversalNetDeviceLinkChart" as reversalNetDeviceLinkChart



List allDevice = new ArrayList();
if ("0".equals(deptId) || null == deptId) {

    List listId
    //陕西环境查询 核心 汇聚
    if (flag.equals("1")) {
        listId = db.table("ndmp_device").column("id").where().eq("device_type", 1).in("station_prop", Arrays.asList(2, 3)).select()
    } else {
        listId = db.table("ndmp_device").column("id").where().eq("device_type", 1).in("station_prop", Arrays.asList(6)).select()
    }


    for (map in listId) {
        allDevice.add(map.get("id"))
    }

} else {
    // 本级设备id
    List listId = db.table("ndmp_group_device_relation").column("device_id").where().eq("group_id", deptId).select()
    for (map in listId) {
        allDevice.add(map.get("deviceId"))
    }

}



Map rs = new HashMap(allDevice.size());

if (!CollectionUtils.isEmpty(allDevice)) {
    List devicelink = db.table("NET_DEVICE_LINK_CHART").where().in("device_id", allDevice).select();


    for (vo in devicelink) {
        vo.put("targetDeviceId", vo.get("targetDeviceid"))
        vo.put("targetDeviceIp", vo.get("targetDeviceip"))
        vo.put("localDeviceId", vo.get("deviceId"))
        vo.remove("targetDeviceip")
        vo.remove("targetDeviceid")
        vo.remove("deviceId")
    }
    rs = devicelink.stream().collect(Collectors.groupingBy(item -> item.get("localDeviceId")));
    //  从redis  取出上下行 接口接口速率 赋值   默认KB
    // this.setIfFlowSpeed(devicelink);
}

/*整理，  将存在连线关系的，互相之间补充完整，例如  核心上路由很少， 基本都是汇聚指向核心
 * 所以核心有被汇聚指向的连线（被动），  但是核心不存在指向汇聚的连线（主动）， 所以要连线也赋值核心被动连线，让
 * 核心有指向汇聚的连线，  目的是为了保证前端页面渲染时，知道每个节点 主动连线，和被动连线，都要给前端
 * */
// log.info("arrangeRelationships  执行前：{}",rs);
//rs = this.arrangeRelationships(rs);
// log.info("arrangeRelationships  执行后：{}",rs);



List allChart = new ArrayList();
rs.values().forEach(
    v -> {
        allChart.addAll(v)
    }
);
Map localAndIdx = allChart.stream().collect(Collectors.groupingBy(v -> v.get("localDeviceId")));
Map targetAndIdx = allChart.stream().collect(Collectors.groupingBy(v -> v.get("targetDeviceId")));

for (entry in localAndIdx.entrySet()) {

    // 将这些反转给
    List netDeviceLinkCharts = targetAndIdx.get(entry.getKey());
    if (!CollectionUtils.isEmpty(netDeviceLinkCharts)) {
        List reversalLinkCharts = reversalNetDeviceLinkChart(netDeviceLinkCharts);
        String localDevice = entry.getKey();
        List update = rs.get(localDevice);
        update.addAll(reversalLinkCharts);

        for (vo in update) {
            vo.put("collectTime", "")
        }

        List linkChart = update.stream().distinct().collect(Collectors.toList());
        rs.put(localDevice, linkChart);
    }


}


return rs;